//
//  ShopCollectCell.m
//  RentTable
//
//  Created by xchuan xchuan on 2024/12/1.
//

#import "ShopCollectCell.h"

@interface ShopCollectCell()

@property (nonatomic, strong) UIButton *shopCollectButton;
@property(nonatomic, strong) UIImageView *orderImageView;
@property (nonatomic, strong) UILabel *hotPriceLabel;
@property (nonatomic, strong) UILabel *hotPriceDayLabel;
@property (nonatomic, strong) UILabel *hotLabel;

@end

@implementation ShopCollectCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self setupUI];
    }
    return self;
}

- (void)setRentModel:(RentModel *)rentModel {
    _rentModel = rentModel;
    
    self.orderImageView.image = [UIImage imageNamed:rentModel.rentImage];
    self.hotPriceLabel.text = rentModel.rentTitle;
    self.hotPriceDayLabel.text = [NSString stringWithFormat:@"¥%.1f/天",rentModel.rentPrice];
}

- (void)setupUI {
    
    UIView *shopTabBackView = [UIView new];
    shopTabBackView.backgroundColor = myRGBHex(0xFFFFFF);
    shopTabBackView.layer.cornerRadius = 20;
    shopTabBackView.layer.masksToBounds = true;
    [shopTabBackView setUserInteractionEnabled:true];
    [self.contentView addSubview:shopTabBackView];
    [shopTabBackView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.trailing.top.mas_equalTo(0);
        make.bottom.mas_equalTo(-20);
    }];
    
    self.orderImageView = [UIImageView new];
    self.orderImageView.image = [UIImage imageNamed:@"1"];
    [shopTabBackView addSubview:self.orderImageView];
    self.orderImageView.layer.cornerRadius = 5;
    self.orderImageView.layer.masksToBounds = true;
    [self.orderImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.mas_equalTo(19);
        make.top.mas_equalTo(12);
        make.size.mas_equalTo(CGSizeMake(95, 95));
    }];
    
    self.hotPriceLabel = [[UILabel alloc] init];
    self.hotPriceLabel.font = [UIFont pingFangSCMediumWithSize:14];
    self.hotPriceLabel.textColor = myRGBHex(0x333333);
    self.hotPriceLabel.text = @"乔氏JOY台球桌标准型成人家用美式黑8二合一中式黑八商用";
    self.hotPriceLabel.textAlignment = NSTextAlignmentLeft;
    self.hotPriceLabel.numberOfLines = 0;
    [shopTabBackView addSubview:self.hotPriceLabel];
    [self.hotPriceLabel sizeToFit];
    [self.hotPriceLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(15);
        make.leading.equalTo(self.orderImageView.mas_trailing).offset(12);
        make.trailing.mas_equalTo(-47);
    }];
    
    self.hotPriceDayLabel = [[UILabel alloc] init];
    self.hotPriceDayLabel.font = [UIFont pingFangSCRegularWithSize:12];
    self.hotPriceDayLabel.textColor = myRGBHex(0xF51D1D);
    self.hotPriceDayLabel.textAlignment = NSTextAlignmentLeft;
    self.hotPriceDayLabel.text = @"¥59.9/天";
    [shopTabBackView addSubview:self.hotPriceDayLabel];
    [self.hotPriceDayLabel sizeToFit];
    [self.hotPriceDayLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.hotPriceLabel.mas_bottom).offset(6);
        make.leading.equalTo(self.orderImageView.mas_trailing).offset(12);
        make.height.mas_equalTo(20);
    }];
    
    self.shopCollectButton = [UIButton buttonWithType:UIButtonTypeCustom];
    [self.shopCollectButton setBackgroundImage:[UIImage imageNamed:@"收藏-选中"] forState:UIControlStateNormal];
    [self.shopCollectButton setBackgroundImage:[UIImage imageNamed:@"收藏-未选中"] forState:UIControlStateSelected];
    [self.shopCollectButton addTarget:self action:@selector(shopCollectButtonClicked:) forControlEvents:UIControlEventTouchUpInside];
    [shopTabBackView addSubview:self.shopCollectButton];
    [self.shopCollectButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.mas_equalTo(-14);
        make.trailing.mas_equalTo(-16);
        make.size.mas_equalTo(CGSizeMake(18, 18));
    }];
    
    
}

- (void)shopCollectButtonClicked:(UIButton *)sender {
//    sender.selected = !sender.selected;
    if (self.shopColle) {
        self.shopColle(self.rentModel);
    }
}

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
